//
// Created by benxb on 2021/10/3.
//

#ifndef BENXDB_CONFIG_H
#define BENXDB_CONFIG_H

#include <cstdint>
#include <string>
#include <common/ini_reader.h>
#include <memory>

namespace benxdb {

static constexpr int INVALID_CHUNK_ID = -1;
static constexpr int RECORD_SIZE = 8;
static constexpr int RECORD_COUNT_PER_CHUNK = 10240;
static constexpr int CHUNK_SIZE = RECORD_SIZE * RECORD_COUNT_PER_CHUNK;
static constexpr int CHUNK_BUFFER_COUNT = 10;
static constexpr int MAX_MEM_TABLE = 10; // max memory table for one dataset
static constexpr int32_t INVALID_PAGE_ID = -1;
static constexpr int PAGE_SIZE = 10240*32;
static constexpr int INDEX_PAGE_SIZE = 1024*32;
static constexpr int MEM_PAGE_SIZE = 16384; // 16KB
static constexpr int VAL_SIZE_IN_PAGE = 1024;
static constexpr int RECORD_PER_CHUNK = 1024;
static std::string DATA_FILE_SUFFIX = ".data";
static std::string META_FILE_SUFFIX = ".meta";
static std::string DELETE_BITMAP_FILE_SUFFIX = ".delmap";
static std::string DATA_DESC_FILE_SUFFIX = ".desc";
static std::string LOG_FILE_SUFFIX = ".memlog";
static std::string INDEX_FILE_SUFFIX = ".index";
static std::string INDEX_DATA_DIR_SUFFIX = ".index.data";
static constexpr int INVALID_LSN = -1;
static constexpr int MAX_PAGES_PER_SEGMENT = 800;
static constexpr int SEGMENT_SPLIT_PAGE_COUNT = 64;

enum CompressStrategy {
    NO_COMPRESS = 0,
    DELTA = 1,
    LZ4 = 2,
    DELTA_LZ4 = 3,
    ZLIB = 4,
    DELTA_ZLIB = 5,
};

enum IndexType {
    SPARSE_INDEX = 0,
    LINEAR_INDEX = 1,
    BTREE_INDEX = 2,
};

enum DatasetType {
    DATASET_XYZ,
    DATASET_XYZ_INTENSITY, // with intensity
    DATASET_XYZ_FRAME // with frame
};

enum CompareSign {EQUAL, LESS_THAN, GREATER_THAN, LESS_EQUAL, GREATER_EQUAL};

using chunk_id_t = int32_t;
using page_id_t = int32_t;
using record_id_t = uint64_t;
using lsn_t = uint64_t;
using index_page_offset_t = int32_t;
using index_page_size_t = int32_t;
using index_seg_id_t = int64_t;


class GlobalConfig {
public:
    static std::string DatasetDir(const std::string& dataset_name);

    static std::string DataFilePath(const std::string& dataset_name);

    static void Init(const std::string& ini_file);

    static std::string MetaFilePath(const std::string &dataset_name);

    static std::string DeleteMapFile(const std::string &dataset_name);

    static std::string LogFilePath(const std::string &dataset_name);

    static std::string DescFilePath(const std::string &dataset_name);


    static std::string data_dir;
    static std::string data_file_name;
    static std::string meta_file_name;
    static std::string delete_bitmap_file_name;
    static std::string data_desc_file_name;
    static std::string log_file_name;
    static std::string index_file_name;
    static std::string index_data_dir_name;
    static CompressStrategy compress_strategy;
    static bool need_log;

    static std::shared_ptr<INIReader> reader_;
};

}

#endif //BENXDB_CONFIG_H
